package com.secondGroup.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.secondGroup.entity.BankCard;
import com.secondGroup.entity.ElectronicAccount;
import com.secondGroup.entity.User;
import com.secondGroup.service.BankCardService;
import com.secondGroup.service.ElectronicAccountService;
import com.secondGroup.vo.StringVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ws
 * @since 2022-05-05
 */
@Controller
@RequestMapping("/electronic-account")
public class ElectronicAccountController {
    @Autowired
    private ElectronicAccountService electronicAccountService;
    @Autowired
    BankCardService bankCardService;

    @RequestMapping("/kaihu")
    public String kaihu(){
    return "kaihu";
    }
    @RequestMapping("/kaihuForm")
    public String kaihuForm(String eName, String payPassword, String cid, String bankName, HttpSession session, Model model,String idNum){

        BankCard one = bankCardService.getOne(new QueryWrapper<BankCard>()
                .lambda()
                .eq(BankCard::getCId, cid));
        if(one!=null){
            model.addAttribute("此卡被绑定过");
            return "error1";
        }
        StringVo kaihu = electronicAccountService.kaihu(idNum,eName, payPassword, cid,  bankName, session);
        if(kaihu.getI()==1){
            model.addAttribute("message",kaihu.getS());
            return "kaihuSuccess";
        }
        model.addAttribute("message","查询不到此卡");
        return "error1";
    }

}
